package org.dromara.common.mybatis.handler;

import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Primary;


/**
 * @desc: 重写mybatis-plus雪花算法生成方法
 * @author: hhl
 * @date：2024/4/2 16:03
 */
@Primary
@Slf4j
public class DefaultIdentifierGenerator implements IdentifierGenerator {

    private SnowflakeIdWorker snowflakeIdWorker = new SnowflakeIdWorker(2);

    @Override
    public Number nextId(Object entity) {
//        log.debug("生成主键Id：{}",entity);
        long id = snowflakeIdWorker.nextId();
//        log.info("生成主键Id={}",id);
        return id;
    }

}
